{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 创建人脸集合\n",
    "import requests,json\n",
    "\n",
    "display_name = \"明星脸集合\"\n",
    "outer_id = \"hnh01\"\n",
    "user_data = \"男明星\"\n",
    "\n",
    "CreateFace_Url = \"https://api-cn.faceplusplus.com/facepp/v3/faceset/create\"\n",
    "payload = {\n",
    "    'api_key': \"GCK9_I6SNKCV6WHagMCtMF5cfQeD8-75\",\n",
    "    'api_secret': \"fH1qAqXt8NMRoZZ-3exc1Mw_IrTlGdz1\",\n",
    "    'display_name':display_name,\n",
    "    'outer_id':outer_id,\n",
    "    'user_data':user_data\n",
    "}\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "r = requests.post(CreateFace_Url, params=payload)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'time_used': 82,\n",
       " 'error_message': 'FACESET_EXIST',\n",
       " 'request_id': '1603532861,4530379b-4ac4-40d0-9306-8941a26d3fff'}"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "r.json()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 获取人脸集合信息\n",
    "GetDetail_Url = \"https://api-cn.faceplusplus.com/facepp/v3/faceset/getdetail\"\n",
    "\n",
    "payload = {\n",
    "    'api_key':\"GCK9_I6SNKCV6WHagMCtMF5cfQeD8-75\",\n",
    "    'api_secret': \"fH1qAqXt8NMRoZZ-3exc1Mw_IrTlGdz1\",\n",
    "    'outer_id':outer_id,\n",
    "}"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [],
   "source": [
    "r = requests.post(GetDetail_Url,params=payload)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'faceset_token': '169125f80dc55f5737d542a5b791f941',\n",
       " 'tags': '',\n",
       " 'time_used': 88,\n",
       " 'user_data': '男明星',\n",
       " 'display_name': '明星脸集合',\n",
       " 'face_tokens': ['8fe67eddcdc25f6954a54543444bf5cd'],\n",
       " 'face_count': 1,\n",
       " 'request_id': '1603532921,7789fd2c-3fa4-442f-9272-28a90b160b4f',\n",
       " 'outer_id': 'hnh01'}"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "r.json()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 增加人脸\n",
    "AddFace_url = \" https://api-cn.faceplusplus.com/facepp/v3/faceset/addface\"\n",
    "\n",
    "payload = {\n",
    "    'api_key': \"GCK9_I6SNKCV6WHagMCtMF5cfQeD8-75\",\n",
    "    'api_secret': \"fH1qAqXt8NMRoZZ-3exc1Mw_IrTlGdz1\",\n",
    "    'faceset_token':'169125f80dc55f5737d542a5b791f941',\n",
    "    'face_tokens':'8fe67eddcdc25f6954a54543444bf5cd',\n",
    "}\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [],
   "source": [
    "r = requests.post(AddFace_url,params=payload)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'faceset_token': '169125f80dc55f5737d542a5b791f941',\n",
       " 'time_used': 95,\n",
       " 'face_count': 1,\n",
       " 'face_added': 0,\n",
       " 'request_id': '1603532970,ca778ebc-c9b3-4c6a-aa39-02b9f1c4fdf3',\n",
       " 'outer_id': 'hnh01',\n",
       " 'failure_detail': []}"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "r.json()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 添加图片进行人脸相似度对比\n",
    "xk = \"http://huangnanhui.gitee.io/api-job/image/xk.jpeg\"\n",
    "lhr = \"http://huangnanhui.gitee.io/api-job/image/lhr.jpg\"\n",
    "wl = \"http://huangnanhui.gitee.io/api-job/image/wl.jpg\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 对比人脸相似度\n",
    "Compare_url = \"https://api-cn.faceplusplus.com/facepp/v3/compare\"\n",
    "\n",
    "payload ={\n",
    "    'api_key': \"GCK9_I6SNKCV6WHagMCtMF5cfQeD8-75\",\n",
    "    'api_secret': \"fH1qAqXt8NMRoZZ-3exc1Mw_IrTlGdz1\",\n",
    "    'image_url1':xk,\n",
    "    'image_url2':wl\n",
    "}"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [],
   "source": [
    "r = requests.post(Compare_url,params=payload)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'faces1': [{'face_rectangle': {'width': 291,\n",
       "    'top': 148,\n",
       "    'left': 86,\n",
       "    'height': 291},\n",
       "   'face_token': 'faacf52c996e0722985b97f40383dbba'}],\n",
       " 'faces2': [{'face_rectangle': {'width': 240,\n",
       "    'top': 206,\n",
       "    'left': 127,\n",
       "    'height': 240},\n",
       "   'face_token': '88fc55d95da486f00368563b6b0aede9'}],\n",
       " 'time_used': 904,\n",
       " 'thresholds': {'1e-3': 62.327, '1e-5': 73.975, '1e-4': 69.101},\n",
       " 'confidence': 55.91,\n",
       " 'image_id2': 'GqX74YmahbeG59LkUV7/kQ==',\n",
       " 'image_id1': 'dzo9PRnQWYYHHWGUY5hw2Q==',\n",
       " 'request_id': '1603533023,7f5820b7-3c59-40e0-a09b-81250fe4724b'}"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "r.json()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.3"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {},
   "toc_section_display": true,
   "toc_window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
